<template>
  <div class="toast" v-show="isShow">
    <div>{{message}}</div>
  </div>
</template>

<script>
export default {
  name: 'Toast',
  data () {
    return {
      message: '添加购物车成功',
      isShow: false
    }
  },
  methods: {
    show (message, duration = 2000) {
      this.message = message
      this.isShow = true

      setTimeout(() => {
        this.isShow = false
      }, duration)
    }
  }
}
</script>

<style lang='scss' scoped>
.toast{
  color: #fff;
  padding: 12px 12px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  background-color: rgba(0,0,0,.7);
  z-index: 999;
  // font-weight: bold;
}
</style>
